<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends CI_Controller
{

   function __construct()
    {
        parent::__construct();

		$unlocked = array('main', 'login');
		$admin_locked=array('admin');
		$staff_locked=array('front_office','housekeeping','massage','laundry','manager','restaurant');
		
				if ( ! $this->site_sentry->is_logged_in() AND ! in_array(strtolower(get_class($this)), $unlocked))
				{
					if(! $this->site_sentry->is_logged_in() AND in_array(strtolower(get_class($this)), $admin_locked) OR in_array(strtolower(get_class($this)), $staff_locked))
					{
						redirect(base_url().'admin_login');
					}
					else
					{
						redirect(base_url().'login');
					}
					
				}//restriction for staff , staff can not access admin
				elseif($this->site_sentry->is_logged_in() AND $this->session->userdata('role_name')==$this->config->item('staff') AND in_array(strtolower(get_class($this)), $admin_locked))
				{
					 $this->session->set_flashdata('action_msg','Anda bukan pengguna yang berwenang');
						redirect(base_url().'admin_login');
				}
				//restriction for admin , admin can not access staff
				elseif($this->site_sentry->is_logged_in() AND $this->session->userdata('role_name')==$this->config->item('admin') AND in_array(strtolower(get_class($this)), $staff_locked))
				{
					 $this->session->set_flashdata('action_msg','Anda bukan pengguna yang berwenang');
						redirect(base_url().'admin_login');
				}
				

				
				

				//$this->output->cache(5);

    }

}
